const babel = require('@babel/core')
const loaderUtils = require('loader-utils')
const validateOptions = require('schema-utils')
const fs = require('fs')

function loader(source) {
  const options = loaderUtils.getOptions(this)
  const cb = this.async()
  const schema = {
    type: 'object',
    properties: {
      text: {
        type: 'string',
      },
      filename: {
        type: 'string',
      },
    }
  }
  console.log('loader => 111')

  validateOptions(schema, options, 'banner-loader')
  babel.transform(source, {
    // presets: options.presets,
    ...options,
    sourceMap: true,
    filename: this.resourcePath.split('/').pop(),
  }, function (err, result) {
    cb(err, result.code, result.map, 'babel-loader')
  })
}

module.exports = loader
